<?php 
if(isset($_GET['id']) && is_numeric($_GET['id'])){
	setcookie("".$_GET['id'], "is_read",time()+7200);	
	include("dbconfig.php");
	// ========================================== ดึงเนื่อหามาแสดงบนรายละเอียดเนื้อหาข่าวที่เลือก =====================================================
	$id = $_GET['id'];
	$sql = "SELECT * FROM article WHERE fix_status = 1 AND article_id =".$id;
	$rsd = mysql_query($sql);
	$row = mysql_fetch_array($rsd);
	$type=$row["fix_article_type"];
	if($type == 3)						
		$reference = "ผู้สัมภาษณ์ :".$row['reference_st']."<br>ผู้ให้สัมภาษณ์ : ".$row['reference_nd']."<br>.. (จำนวนครั้งที่อ่าน ".$row["reader_count"]." ครั้ง";
	else
		$reference = "ผู้เขียน:".$row['reference_st']."<br>..(จำนวนครั้งที่อ่าน) ".$row["reader_count"]." ครั้ง";
	
	$date = new DateTime($row['inserted_date_time']);
	
	if((bool)preg_match('#<img[^>]+src=[\'"]([^\'"]+)[\'"]#', html_entity_decode($row['description']), $matches))
	{
	   $imageFound = $matches[0];
	   $src = substr($imageFound, strpos($imageFound, "src"));
	}else{
	   $src = "src=\"/images/default_image.png\"";
	}
	$image = str_replace("src=\"","http://pataniforum.com",$src);
	$title = $row['title'];
	$description = mb_substr(trim(strip_tags(html_entity_decode($row['description']))),0,200,'UTF-8');
?>
<!DOCTYPE HTML>
<html>
   <head>
      <title>PATANI FORUM</title>
	  <meta name="stats-in-th" content="1134" />
	  <meta http-equiv="content-language" content="th" />
	  <meta content="ศูนย์ข่าว Patani Forum" name="description"/>
	  <meta content="Patani,Forum,ปาตานี, Pattani,3 จังหวัด,ชายแดนใต้,นราธิวาศ,ยะลา,เหตุการณ์,ปัตตานี" name="Keywords"/>
	  <meta name="revisit-after" content="7 days" />
	  <meta name="robots" content="index,follow"/>	
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

	  <meta property="og:type" content="website" />
	  <meta property="og:title" content="<?=$title?>" />
	  <meta property="og:description" content="<?=$description?>" />
	  <meta property="og:image" content="<?=$image?>" />
	  <meta property="og:image:type" content="image/jpeg" />
	  <meta property="og:site_name" content="pataniforum" />

	  <link rel="SHORTCUT ICON" href="images/icon-pataniforum64.ico">
      <link rel='stylesheet' type='text/css' href='http://fonts.googleapis.com/css?family=Roboto+Slab:400,700' >
      <link rel="stylesheet" type="text/css" href="css/font-awesome.min.css" media="all">
      <link rel="stylesheet" type="text/css" href="css/framework.css" media="all">
      <link rel="stylesheet" type="text/css" href="css/flexslider.css" media="screen">
      <link rel="stylesheet" type="text/css" href="css/magnific-popup.css" media="screen">
      <link rel="stylesheet" type="text/css" href="css/superfish.css" media="all">
      <link rel="stylesheet" type="text/css" href="css/superfish-vertical.css" media="all">
      <link rel="stylesheet" type="text/css" href="style.css" media="all">
      <script src="js/jquery.min.js"></script>
   </head>
   <body>
   	
	  <?php include ('offcanvas.php');?>	
   
      <header id="masthead">
			<img src="images/header.gif" width="100%">
			
         <!-- .container -->
		  <div class="navbar-social floatright">
               <a href="https://www.facebook.com/pataniforum" title="Facebook" target="_blank"><img src="images/facebook_32.png"></a>
               <a href="#" title="Twitter"><img src="images/twitter_32.png"></a>
               <a href="#" title="Youtube"><img src="images/youtube_32.png"></a> 
            </div>
      </header>
	   
      <!-- #masthead -->
      <div id="navbar" class="navbar navbar-main" role="navigation">
         <div class="prl-container textcenter">
			<?php include ('nav.php');?>
            <form action="search.php" method="post">
				<span class="navbar-search floatright">
			   		<a id="navbar-toggle-search" class="navbar-toggle navbar-toggle-search floatright" href="#" ></a>
					<input type="text" placeholder="Search..." class="navbar-search-input" name="search" />
				</span> 
			</form>
            <a class="navbar-toggle navbar-toggle-mail floatright" href="contact.php"></a>
         </div>
      </div>
      <!-- #navbar -->
      <div id="main" role="main">
		<div class="prl-container">
			
			<div class="prl-grid">
				<section class="prl-span-8">
					 <article class="prl-article w-box">
					<div class="w-box-inner">
					<?php
						$row["reader_count"] = $row['reader_count'];
						//บันทึกจำนวนครั้งที่คนอ่าน โดย หากอ่านติด ๆ กันจะบันทึกครั้งเดียว (ต้อง 2 ชม ผ่านไป ถึงจะนับใหม่ ซึ่งค่าจะเก็บใน cookie)
						$row["reader_count"] = ($row['reader_count']+1);					
						$sql = "UPDATE article SET reader_count  =";
						$sql .= $row["reader_count"];
						$sql .=" WHERE article_id = ".$id;
						$objQuery = mysql_query($sql);						
					?> 
					<h1><?=$title?></h1>
					<div class="prl-article-meta"><span><i class="fa fa-clock-o"></i> <?php echo $date->format('d/m/Y H:i:s');?></span> <span><?php echo $reference?></span> <span><i class="fa fa-folder-open"></i> </span></div>
					<?php 
						include("plugin/facebook/like_button.php");
						include("plugin/google/plus_google.php");
						echo html_entity_decode($row['description']);
					?>
						<p class="prl-article-tags"><span class="prl-article-tags-header">Tags:</span> <a href="">Patani</a> <a href="">Forum</a> <a href="">News</a> <a href="">Interview</a> <a href="">Deep South</a></p>
					
					</div>				
					<div class="prl-article-bottom clearfix">
						<div class="prl-article-share floatleft">
							<a href="https://www.facebook.com/pataniforum" class="fa fa-facebook" target="_blank"></a>
							<a href="" class="fa fa-twitter"></a>
							<a href="" class="fa fa-google-plus"></a>
							<a href="" class="fa fa-youtube"></a>
						</div>
					</div>
					</article>
					<?php 
						include 'related-post.php';
					?>
				</section>
				<aside id="sidebar" class="prl-span-4">
					<?php include ('sidebar.php');?>
				</aside>
			</div><!--.prl-grid -->
		</div><!-- .container-->

	<?php include ('footer.php');?>
<?php 
}else{
	header("Location: http://www.pataniforum.com");
}
?>